<template>
    <div>
        <div class="basicWrapper" v-if="allShow">
            <!-- 基本设置 -->
            <div class="basicItem">
                <div class="setNew">
                    <div class="cartitle">
                        <span class="smallTip"></span>
                        <h3>基本设置</h3>
                    </div>
                </div>
                <div class="basicContent">
                    <ul>
                        <li>
                            <div class="basicLeft">
                                <h3>用户信息</h3>
                                <p>可修改自己的个人信息: 个人简介及头像。</p>
                            </div>
                            <span @click="handleChange()">修改</span>
                        </li>
                        <li v-if="userInfo.registrationType === '1'">
                            <div class="basicLeft">
                                <h3>个人实名认证</h3>
                                <div>
                                    <p style="display:block;">
                                       {{ realTextPersonal }}
                                    </p>
                                    <p style="display:block;" class="newExport">
                                       {{ expertInfo }}
                                    </p>
                                </div>
                            </div>
                            <span @click="handleName()">{{ realBtnPersonal }}</span>
                        </li>
                        <li v-if="userInfo.registrationType !== '1'">
                            <div class="basicLeft">
                                <h3>机构认证</h3>
                                <div>
                                    <p>{{ realText }}</p>
                                    <!-- <el-button class="realBtn" type="primary" @click="toLookRecord" plain
                                        size="mini">查看企业认证申请审核记录</el-button> -->
                                </div>
                            </div>
                            <span @click="handleLogon()">{{ realBtn }}</span>
                        </li>
                        <li>
                            <div class="basicLeft">
                                <h3>绑定邮箱</h3>
                                <p v-if="userInfo.email !== ''">已绑定邮箱：{{ userInfo.email }}</p>
                                <p v-else>未绑定邮箱</p>
                            </div>
                            <span @click="handleEmail()">修改</span>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- 安全设置 -->
            <div class="basicItem">
                <div class="setNew">
                    <div class="cartitle">
                        <span class="smallTip"></span>
                        <h3>安全设置</h3>
                    </div>
                </div>
                <div class="basicContent">
                    <ul>
                        <li>
                            <div class="basicLeft">
                                <h3>账户密码</h3>
                                <p>当前密码强度：<span>强</span></p>
                            </div>
                            <span @click="handleSign()">修改</span>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- 新消息通知 -->
            <div class="basicItem">
                <div class="setNew">
                    <div class="cartitle">
                        <span class="smallTip"></span>
                        <h3>新消息通知</h3>
                    </div>
                </div>
                <div class="basicContent">
                    <ul>
                        <li>
                            <div class="basicLeft">
                                <h3>系统通知</h3>
                                <p>系统消息将以站内信息的形式进行通知。</p>
                            </div>
                            <div class="rightSwitch">
                                <el-switch active-value="0" inactive-value="1" v-model="ifNews" @change="notiFication"
                                    active-color="#1890FF" active-text="开" inactive-color="#999999" inactive-text="关">
                                </el-switch>
                            </div>
                        </li>
                        <!-- <li>
                            <div class="basicLeft">
                                <h3>短信通知</h3>
                                <p>系统消息将以短信的形式进行通知。</p>
                            </div>
                            <div class="rightSwitch">
                                <el-switch active-value="1" inactive-value="0" v-model="sysMsg2" active-color="#1890FF"
                                    active-text="开" inactive-color="#999999" inactive-text="关">
                                </el-switch>
                            </div>
                        </li> -->
                        <!-- <li>
                            <div class="basicLeft">
                                <h3>邮件通知</h3>
                                <p>系统消息将以邮件的形式进行通知。</p>
                            </div>
                            <div class="rightSwitch">
                                <el-switch active-value="1" inactive-value="0" v-model="sysMsg3" active-color="#1890FF"
                                    active-text="开" inactive-color="#999999" inactive-text="关">
                                </el-switch>
                            </div>
                        </li> -->
                    </ul>
                </div>
            </div>
            <!-- 查看实名认证申请记录 -->
            <el-dialog title="查看认证申请记录" :visible.sync="dialogVisible" width="50%">
                <el-table :data="recordData" style="width: 100%" :header-cell-style="{ background: '#f0f2f5' }">
                    <el-table-column label="序号" width="48" type="index"></el-table-column>
                    <el-table-column prop="logInfo" label="信息" show-overflow-tooltip>
                    </el-table-column>

                    <!-- <el-table-column prop="operationType" label="操作类型" show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span v-if="scope.row.operationType === '0'">个人用户绑定机构相关</span>
                            <span v-if="scope.row.operationType === '1'">机构账号相关</span>
                        </template>
                    </el-table-column> -->
                    <el-table-column prop="operationTypeDateils" label="审核状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.operationTypeDateils === '0'">申请</span>
                            <span v-if="scope.row.operationTypeDateils === '1'">取消</span>
                            <span v-if="scope.row.operationTypeDateils === '2'">审核通过</span>
                            <span v-if="scope.row.operationTypeDateils === '3'">审核未通过</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="operationInfo" label="审核意见">
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <div class="poolPage">
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="params.pageNumber" :page-sizes="[10, 20, 30]" :page-size="params.pageSize"
                        layout="total, prev, pager, next, jumper" :total="total">
                    </el-pagination>
                </div>
            </el-dialog>
        </div>
        <!-- 用户信息 -->
        <ChangeInfo @handleBack="handleBack" v-if="isChange" />

        <!-- 实名认证 -->
        <ChangeRealName @handleBacka="handleBacka" v-if="isName" />

        <!-- 注册信息 -->
        <ChangeRegInfo @handleBackb="handleBackb" v-if="isLogin" />

        <!-- 绑定邮箱 -->
        <ChangeEmail @handleBackc="handleBackc" v-if="isEmail" />

       

        <!-- 账户密码 -->
        <ChangePwd @handleBackf="handleBackf" v-if="isSign" />

        <!-- 专家认证 -->
        <ChangeInfoPhone @handleBacke="handleBacke" v-if="isHandset" />

        <!-- 企业邀请码 -->
        <InvitationCode ref="detailContent" />
    </div>
</template>
<script>
import { getUserInfo2, messageNotification, invitationGenerate, invitationViev } from "@/request/api/user"
import ChangeInfo from "./changeInfo.vue"
import ChangeRealName from "./changeRealName.vue"
import ChangeRegInfo from "./changeRegInfo.vue"
import ChangeEmail from "./changeEmail.vue"
import ChangePwd from "./changePwd.vue"
import ChangeInfoPhone from "./changeInfoPhone.vue"
import InvitationCode from "./invitationCode.vue"

export default {
    components: {
        ChangeInfo,
        ChangeRealName,
        ChangeRegInfo,
        ChangeEmail,
        ChangePwd,
        ChangeInfoPhone,
        InvitationCode

    },
    data() {
        return {
            expertInfo:'',//专家信息
            isHandset: false,
            isSign: false,
            isSpecialist: false,
            isEmail: false,
            isLogin: false,
            isName: false,
            isChange: false,
            isShow: true,
            allShow: true,
            sysMsg1: "0",
            sysMsg2: "0",
            sysMsg3: "0",
            userInfo: {},
            realText: '',//
            realBtn: '认证',
            dialogVisible: false,
            params: {
                operationType: 0,
                orderByColumn: 'operationTime',
                isAsc: 'desc',
                page: 1,
                pageSize: 10
            },
            ifNews: '',

            recordData: [],
            total: 0,
            expertDesc: '',//专家描述
            expertBtn: '',//专家按钮
            notification: [],//系统通知
            inviteCode: '',
            name: this.$route.query.name,
            realBtnPersonal: '',
            realTextPersonal: '',
            invitationText: '普通用户可填写企业邀请码申请加入企业',
            invitationBtn: '填写'
        }
    },
    created() {
        if (this.$route.query.name === '认证') {
            this.handleLogon()
        }
        this.getInfo()
        this.getIsExpert()
        // this.getInvitation()	
        // this.notiFication()
    },


    methods: {
        // 获取用户信息
        getInfo() {
            getUserInfo2().then(res => {
                if (res.data.code === 200) {
                    this.userInfo = res.data.result
                    if (this.userInfo.registrationType == '1') {//个人用户
                        if (this.userInfo.iuiCertification === '0') {//未认证
                            this.realBtnPersonal = '认证'
                            this.realTextPersonal = "未进行实名认证";
                        } else if (this.userInfo.iuiCertification === '1') {//实名认证通过
                            this.realBtnPersonal = '修改'
                            this.realTextPersonal = "实名认证通过，对部分信息可进行信息变更。"
                        }
                        if(this.userInfo.serveExpert=='0'){//
                            this.expertInfo=''
                        }else if(this.userInfo.serveExpert=='1'){//通过
                            this.expertInfo='已认证成为专家'
                        }else if(this.userInfo.serveExpert=='2'){//待审核
                            this.expertInfo='专家认证申请正在审核中'
                        }else if(this.userInfo.serveExpert=='3'){//审核驳回
                            this.expertInfo='专家认证申请已被驳回，审核意见：'+this.userInfo.auditOpinion
                        }
                        // // 判断个人用户申请加入企业
                        // if (this.userInfo.ifExamine == '3') {//待审核
                        //     this.invitationText = '待审核'
                        //     this.invitationBtn = ''
                        // } else if (this.userInfo.ifExamine == '2') {//审核驳回   
                        //     this.invitationText = '审核意见,' + this.userInfo.auditOpinion
                        //     this.invitationBtn = '填写'
                        // } else if (this.userInfo.ifExamine == '1') {//审核通过
                        //     if (this.userInfo.companyInfo !== undefined) {
                        //         this.invitationText = this.userInfo.companyInfo.name
                        //         this.invitationBtn = ''
                        //     }
                        // }
                    } else {//企业用户
                        if (this.userInfo.iuiCertification === '0') {//未认证
                            this.realBtn = '认证'
                            this.realText = "未进行企业认证";
                        } else if (this.userInfo.iuiCertification === '1') {//实名认证通过
                            this.realBtn = '修改'
                            this.realText = "企业认证信息已通过，可修改信息"
                        } else if (this.userInfo.iuiCertification === '2') {//审核中(已提交实名认证)
                            this.realBtn = ''
                            this.realText = "您提交的认证信息正在审核中，请耐心等待";
                        } else if (this.userInfo.iuiCertification === '3') {//实名认证驳回
                            this.realBtn = '修改'
                            this.realText = "您提交的认证信息已被驳回，请重新修改认证信息；审核意见："+this.userInfo.auditOpinion;
                        }
                    }

                    if (this.userInfo.registrationType === '1' && this.userInfo.iuiCertification === '1') {
                        this.isShow = true
                    } else {
                        this.isShow = false
                    }
                    this.ifNews = this.userInfo.ifNews
                    if (this.userInfo.registrationType !== '1') {
                        this.getInvitation()
                    }
                }
            })


        },
        // 查看企业注册申请记录
        toLookRecord() {
            this.dialogVisible = true
            getExamineRecord().then(res => {
                if (res.data.code === 200) {
                    this.recordData = res.data.result.items
                    this.total = res.data.result.total
                }
            })
        },
        // 查看个人注册申请记录
        toLookRecord2() {
            this.dialogVisible = true
            getExamineUserRecord(this.params).then(res => {
                if (res.data.code === 200) {
                    this.recordData = res.data.result.items
                    this.total = res.data.result.total
                }
            })
        },

        // 系统通知
        notiFication(val) {
            let params = {
                ifNews: val
            }
            messageNotification(params, {}).then(res => {
                if (res.data.code === 200) {
                    this.userInfo.ifNews = this.ifNews
                }
            })
        },
        handleSizeChange(val) {
            this.params.pageSize = val;
            this.params.page = 1;
            if (this.userInfo.registrationType === '0') {//企业
                this.toLookRecord()
            } else if (this.userInfo.registrationType === '1') {//个人
                this.toLookRecord2()
            }
        },
        handleCurrentChange(val) {
            this.params.page = val;
            if (this.userInfo.registrationType === '0') {//企业
                this.toLookRecord()
            } else if (this.userInfo.registrationType === '1') {//个人
                this.toLookRecord2()
            }
        },
        // 查询是否认证过服务专家
        getIsExpert() {
            lookExpertIs().then(res => {
                console.log(res)
                if (res.data.code === 200) {
                    let zt = res.data.result.zt
                    if (zt === '0') {//待审核
                        this.expertBtn = '查看'
                        this.expertDesc = "您提交的注册申请正在审核中。";
                    } else if (zt === '1') {//审核通过
                        this.expertBtn = '查看'
                        this.expertDesc = "您提交的注册申请已通过审核"
                    } else if (zt === '2') {//审核驳回
                        this.expertBtn = '重新申请'
                        this.expertDesc = "您提交的注册申请审核未通过，您可重新申请。";
                    } else if (zt === '3') {//已提交注销申请
                        this.expertBtn = '查看'
                        this.expertDesc = "您已提交注销申请，请等待管理员审核。";
                    } else if (zt === '4') {//注销通过
                        this.expertBtn = '申请'
                        this.expertDesc = "您提交的注销申请已审核通过，您可重新申请！";
                    } else if (zt === '5') {//注销驳回
                        this.expertBtn = '查看'
                        this.expertDesc = "您提交的注销申请已被驳回。";
                    } else if (zt === '6') {//未认证
                        this.expertBtn = '申请'
                        this.expertDesc = "可申请成为服务专家";
                    }
                }
            })
        },
        // 修改用户
        handleChange() {
            this.isChange = true
            this.allShow = false
        },
        // 返回
        handleBack() {
            this.isChange = false
            this.allShow = true
        },

        // 实名认证
        handleName() {
            this.isName = true
            this.allShow = false

        },
        // 返回
        handleBacka() {
            this.isName = false
            this.allShow = true
            this.getInfo()
        },

        // 实名认证
        handleLogon() {
            this.isLogin = true
            this.allShow = false
        },
        // 返回
        handleBackb() {
            this.isLogin = false
            this.allShow = true
            this.getInfo()
        },
        // 绑定邮箱
        handleEmail() {
            this.isEmail = true
            this.allShow = false
            this.getInfo()
        },
        // 返回
        handleBackc() {
            this.isEmail = false
            this.allShow = true
            this.getInfo()
        },
        // 专家认证
        handleSpecialist() {
            this.isSpecialist = true
            this.allShow = false
        },

        // 返回
        handleBackd() {
            this.isSpecialist = false
            this.allShow = true
            this.getInfo()
            this.getIsExpert()
        },

        // 账户密码
        handleSign() {
            this.isSign = true
            this.allShow = false
        },
        // 返回
        handleBackf() {
            this.isSign = false
            this.allShow = true
            this.getInfo()
        },

        // 修改手机号
        handleHandset() {
            this.isHandset = true
            this.allShow = false

        },
        // 返回
        handleBacke() {
            this.isHandset = false
            this.allShow = true
            // this.getInfo()
        },
        // 企业邀请码
        hanldeDetail() {
            this.$refs.detailContent.open()
        },
        // 更新企业邀请码
        hanldeUpdateCode() {
            if (this.userInfo.iuiCertification == '1') {//判断企业是否认证
                this.$confirm("确认更新吗?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    invitationGenerate().then((res) => {
                        if (res.data.code === 200) {
                            this.$message({
                                message: res.data.message,
                                type: "success",
                            });
                            this.getInvitation()
                        } else {
                            this.$message.error(res.data.message);
                        }
                    });
                })
            } else {
                this.$message({
                    message: '先进行企业认证！',
                    type: "warning",
                });
            }
        },
        //查看企业邀请码
        getInvitation() {
            invitationViev().then(res => {
                if (res.data.code === 200) {
                    this.inviteCode = res.data.result
                }
            })
        },

    }
}
</script>
<style lang="less" scoped>
@import "./basicInfo.less";
.newExport{
    float: none !important;
    color: #5187eb !important;
    font-size: 16px !important;
    margin-top: 0;
}
</style>

